package com.itheima.dianming.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.dianming.mapper.StuInterfaceTestLogMapper;
import com.itheima.dianming.mapper.StuProjectMapper;
import com.itheima.dianming.pojo.domain.StuInterfaceTestLog;
import com.itheima.dianming.pojo.domain.StuProject;
import com.itheima.dianming.service.StuProjectService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StuProjectServiceImpl
        extends ServiceImpl<StuProjectMapper, StuProject> implements StuProjectService {
    @Autowired
    private StuProjectMapper stuProjectMapper;

    @Autowired
    private StuInterfaceTestLogMapper testLogMapper;

    @Override
    public IPage<StuProject> pageQuery(IPage<StuProject> pageInfo, String name,Long projectId) {
        IPage<StuProject> stuProjectIPage = stuProjectMapper.queryPage(pageInfo, name, projectId);

        stuProjectIPage.getRecords().stream().forEach(stu->{

            StuInterfaceTestLog log = testLogMapper.selectByStuId(stu.getStuId(),stu.getProjectId());
            if(log!=null){
                if(log.getDetail().length()>100){
                    stu.setDetail(log.getDetail().substring(0,99));
                }else {
                    stu.setDetail(log.getDetail());
                }
            }

        });

        return stuProjectIPage;
    }
}
